package com.chapter_4;

import java.io.IOException;

/**
 * @Author: Timo
 * @Date: 2019/5/15 12:06
 * @Description: 用于定期保存数据内容。
 */
public class SaverThread extends Thread {

    private final Data data;

    public SaverThread(String name, Data data) {
        super(name);
        this.data = data;
    }


    @Override
    public void run() {
        try {

            while (true) {
                //保存文件的内容
                data.save();
                // 每个1s就保存一次
                Thread.sleep(1_000);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
